home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_09 / barbu2 / modal3.cpp < prev    next >
C/C++ Source or Header  |  1995-05-11  |  4KB  |  162 lines

  1. // MODAL3, MODALDLG dynamic helper functions
  2. //////////////////////////////////////////////////////
  3. #include "MODALDLG.HPP"
  4.  
  5. BOOL CALLBACK _export
  6. FindCtlsEnumProc(HWND hWnd, LPARAM l)
  7. {
  8. STR s(81);
  9. HFONT _hNoBold = (HFONT)l;
  10. GetClassName(hWnd, (char*)(const char*)s, s.space());
  11. s.toupper();
  12. if(s == "STATIC" || s == "BUTTON")
  13.     SendMessage(hWnd, WM_SETFONT,
  14.                 (WPARAM)_hNoBold, 0);
  15. return TRUE;
  16. }
  17.  
  18. void MODALDLG::_thinFontJob()
  19. {
  20. LOGFONT lFont;
  21. HFONT hF;
  22. if(!IsWindow(_hDlg))
  23.     return;
  24. // Get font and create version that is not bold.
  25. if (0 == (hF = (HFONT)SendMessage(
  26.                         GetWindow(_hDlg, GW_CHILD),
  27.                         WM_GETFONT, 0, 0L)))
  28.     return;
  29. if (!GetObject(hF, sizeof(LOGFONT), (LPSTR) &lFont))
  30.     return;
  31. lFont.lfWeight = FW_NORMAL;
  32. if (0 == (hF = CreateFontIndirect((LPLOGFONT)
  33.                                     &lFont)))
  34.     return;
  35. BOOL (CALLBACK *lpfnEnum)(HWND,LPARAM);
  36. lpfnEnum = (BOOL (CALLBACK*)(HWND,LONG))
  37.                 MakeProcInstance(
  38.                     (FARPROC)FindCtlsEnumProc, _hI);
  39. EnumChildWindows(_hDlg,
  40.             (BOOL (CALLBACK*)(HWND,LPARAM))lpfnEnum,
  41.             (LPARAM)hF);
  42. FreeProcInstance((FARPROC)lpfnEnum) ;
  43. _hThinFont = hF;
  44. }
  45.  
  46. void MODALDLG::_centerOnScreen()
  47. {
  48. int xS = GetSystemMetrics(SM_CXSCREEN);
  49. int yS = GetSystemMetrics(SM_CYSCREEN);
  50. RECT r;
  51. GetWindowRect(_hDlg, &r);
  52. int w = r.right-r.left + 1;
  53. int h = r.bottom-r.top + 1;
  54. MoveWindow(_hDlg, (xS-w)/2, (yS-h)/2, w, h, FALSE);
  55. }
  56.  
  57. void MODALDLG::_drawTab(LPDRAWITEMSTRUCT lpdis)
  58. {
  59. POINT tp[7];
  60. RECT r = lpdis->rcItem;
  61. RECT rF;
  62. STR Buf(80);
  63.  
  64. BOOL bPushed = lpdis->itemState & ODS_SELECTED;
  65. BOOL bFocus  = lpdis->itemState & ODS_FOCUS;
  66.  
  67. // This optimization still works under Win 3.1x
  68. if(lpdis->itemAction & ODA_FOCUS && !bFocus)
  69.     return;
  70.  
  71. // Nothing special to draw if simply pushed
  72. if(bPushed)
  73.     return;
  74.  
  75. FillRect(lpdis->hDC, &(lpdis->rcItem),
  76.             (HBRUSH)GetStockObject(LTGRAY_BRUSH));
  77. r.top++;
  78.  
  79. HPEN hPW = CreatePen(PS_SOLID, 1,
  80.                 GetSysColor(COLOR_HIGHLIGHTTEXT));
  81.  
  82. if((UINT)(-1) == lpdis->CtlID){
  83.     tp[0].x = r.left;
  84.     tp[1].x = r.right+1;
  85.     tp[0].y = tp[1].y = r.bottom-2;
  86.     Polyline(lpdis->hDC, tp, 2);
  87.  
  88.     HPEN hSav = (HPEN)SelectObject(lpdis->hDC,
  89.                                 (HGDIOBJ)hPW);
  90.     tp[0].y = tp[1].y = r.bottom-1;
  91.     Polyline(lpdis->hDC, tp, 2);
  92.     DeleteObject(SelectObject(lpdis->hDC, hSav));
  93.     return;
  94.     }
  95.  
  96. BOOL bTheOne = (lpdis->CtlID == _nActiveGroup + 3);
  97.  
  98. tp[0].x = r.left;
  99. tp[0].y = r.bottom-2;
  100. tp[1].x = r.left;
  101. tp[1].y = r.top+2;
  102. tp[2].x = r.left+2;
  103. tp[2].y = r.top;
  104. tp[3].x  = r.right-3;
  105. tp[3].y  = r.top;
  106. tp[4].x  = r.right-1;
  107. tp[4].y  = r.top+2;
  108. tp[5].x  = r.right-1;
  109. tp[5].y  = r. bottom-2;
  110.  
  111. if(bTheOne){
  112.     tp[6].x  = r.right-1;
  113.     tp[6].y  = r. bottom-1;
  114.     }
  115. else{
  116.     tp[6] = tp[0];
  117.     }
  118. Polyline(lpdis->hDC, tp, 7);
  119.  
  120. HPEN hSav = (HPEN)SelectObject(lpdis->hDC,
  121.                                 (HGDIOBJ)hPW);
  122. if(bTheOne){
  123.     tp[0].x = r.left;
  124.     tp[0].y = r.bottom-1;
  125.     tp[1].x = r.left+1;
  126.     tp[1].y = r.bottom-1;
  127.     tp[2].x = r.left+1;
  128.     tp[2].y = r.top+2;
  129.     tp[3].x = r.left+2;
  130.     tp[3].y = r.top+1;
  131.     tp[4].x = r.right-2;
  132.     tp[4].y = r.top+1;
  133.     Polyline(lpdis->hDC, tp, 5);
  134.     }
  135. else{
  136.     tp[0].x = r.left;
  137.     tp[1].x = r.right+1;
  138.     tp[0].y = tp[1].y = r.bottom-1;
  139.     Polyline(lpdis->hDC, tp, 2);
  140.     }
  141. DeleteObject(SelectObject(lpdis->hDC, hSav));
  142.  
  143. GetWindowText(lpdis->hwndItem,
  144.             (char*)(const char*)Buf, Buf.space());
  145. rF.left = r.left + 1;
  146. rF.top = r.top + 1;
  147. rF.right = r.right + 1;
  148. rF.bottom = r.bottom + 1;
  149. int oldMode = SetBkMode(lpdis->hDC, TRANSPARENT);
  150. if(bTheOne){
  151.     COLORREF oldC = SetTextColor(lpdis->hDC,
  152.                     GetSysColor(COLOR_HIGHLIGHTTEXT));
  153.     DrawText(lpdis->hDC, Buf, -1, &rF,
  154.         DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  155.     SetTextColor(lpdis->hDC, oldC);
  156.     }
  157. DrawText(lpdis->hDC, Buf, -1, &r,
  158.         DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  159. SetBkMode(lpdis->hDC, oldMode);
  160. }
  161.  
  162.